﻿Imports DevExpress.XtraReports.UI
Public Class FormMesWorkReportList
    Dim objPgdMesWorkReport As New clsPgdMesWorkReport
    Dim txt As TextBox
    Private Sub FormMesWorkReportList_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim startDate As String = Date.Now.ToShortDateString()
        txtStartDate.Text = startDate
        Dim endDate As String = Date.Now.ToShortDateString()
        txtEndDate.Text = endDate
        setDgvData()
    End Sub

    Private Sub btnSearch_Click(sender As Object, e As EventArgs) Handles btnSearch.Click
        setDgvData()
    End Sub

    Private Sub setDgvData()
        If String.IsNullOrEmpty(txtStartDate.Text.Trim()) = False And String.IsNullOrEmpty(txtEndDate.Text.Trim()) = False Then
            Dim dt As DataTable = objPgdMesWorkReport.getList(txtStartDate.Text & " 00:00:00.000", txtEndDate.Text & " 23:59:59.999")
            If dt.Rows.Count > 0 Then
                dt.Columns.Add("validity_name")
                For Each row As DataRow In dt.Rows
                    If row("validity") = "0" Then
                        row("validity_name") = "无效"
                    Else
                        row("validity_name") = "有效"
                    End If
                Next
            End If
            dgv.AutoGenerateColumns = False
            dgv.DataSource = dt
        Else
            MsgBox("请选择开始时间和结束时间", MsgBoxStyle.Information, "提示")
        End If
    End Sub

    Private Sub txt_MouseClick(sender As Object, e As MouseEventArgs) Handles txtStartDate.MouseClick, txtEndDate.MouseClick
        txt = CType(sender, TextBox)
        DateNavigator1.Left = txt.Left
        DateNavigator1.Top = txt.Location.Y + txt.Height
        DateNavigator1.Visible = True
    End Sub


    Private Sub DateNavigator1_DateTimeChanged(sender As Object, e As EventArgs) Handles DateNavigator1.DateTimeChanged
        txt.Text = DateNavigator1.DateTime.ToShortDateString()
        DateNavigator1.Visible = False
    End Sub

    Private Sub btnProjectDetails_Click(sender As Object, e As EventArgs) Handles btnProjectDetails.Click
        If dgv.SelectedRows.Count > 0 Then
            Dim formMesProjectList As New FormMesProjectList()
            formMesProjectList.mes_project_code = dgv.SelectedRows(0).Cells("mes_project_code").Value.ToString()
            formMesProjectList.mes_project_name = dgv.SelectedRows(0).Cells("mes_project_name").Value.ToString()
            formMesProjectList.ShowDialog(Me)
        End If
    End Sub

    Private Sub btnPrint_Click(sender As Object, e As EventArgs) Handles btnPrint.Click
        If dgv.SelectedRows.Count > 0 Then
            Dim report As New XtraReport3()
            Dim printTool As New ReportPrintTool(report)
            report.Xr_lbl_support_model.Text = dgv.SelectedRows(0).Cells("Colprod_spec_name").Value.ToString()
            report.Xr_lbl_project_name.Text = dgv.SelectedRows(0).Cells("mes_project_name").Value.ToString()
            report.Xr_lbl_project_code.Text = dgv.SelectedRows(0).Cells("project_no").Value.ToString() '项目编号
            report.Xr_lbl_yzz_DateTime.Text = dgv.SelectedRows(0).Cells("org_time").Value.ToString() '预组装时间
            report.XrBarCode1.Text = dgv.SelectedRows(0).Cells("prod_id").Value.ToString() '生产编号
            report.Xr_lbl_jp_type.Text = dgv.SelectedRows(0).Cells("ColModel").Value.ToString() '胶料类型     
            report.Xr_lbl_gyh.Text = dgv.SelectedRows(0).Cells("steel_seal_no").Value.ToString() '钢印号
            report.Xr_lbl_location.Text = dgv.SelectedRows(0).Cells("location").Value.ToString() '库位编号
            printTool.Print()
        End If
    End Sub
End Class